home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / dvglue10.arc / TVFBUILD.C < prev    next >
C/C++ Source or Header  |  1988-08-13  |  4KB  |  110 lines

  1. /*=======================================================*/
  2. /*  TVFBUILD.C                                           */
  3. /*                                                       */
  4. /*  (c) Copyright 1988 Ralf Brown  All Rights Reserved   */
  5. /*  May be freely copied for noncommercial use, so long  */
  6. /*  as this copyright notice remains intact, and any     */
  7. /*  changes are marked in the comment blocks preceding   */
  8. /*  functions.                                           */
  9. /*=======================================================*/
  10.  
  11. #include "tvapi.h"
  12. #include "tvstream.h"
  13.  
  14. /*=============================================*/
  15. /* TVfld_build_header  start creation of a     */
  16. /*                     field table definition  */
  17. /*   Ralf Brown 7/5/88                         */
  18. /*=============================================*/
  19.  
  20. BYTE * pascal TVfld_build_header(int num_fields,int screen_type,int curr_attr,int selected_attr)
  21. {
  22.    BYTE *stream ;
  23.    int stream_len = sizeof(FT_HEADER) + 6 + num_fields*(sizeof(FT_ENTRY) + 5) ;
  24.    int i, count ;
  25.  
  26.    if ((stream = (BYTE *)malloc( stream_len + 4)) == NULL)
  27.       return NULL ;
  28.    stream[0] = 0x1B ;
  29.    stream[1] = 0 ;
  30.    *(int *)(stream+2) = stream_len ;
  31.    stream[4] = 0xE5 ;  /*  \ force field table entries to be 8 bytes */
  32.    stream[5] = 0x10 ;  /*  /                                         */
  33.    stream[6] = 0xFF ;
  34.    stream[7] = num_fields ;
  35.    stream[8] = screen_type ;
  36.    stream[9] = 0 ;
  37.    stream[10] = 0 ;
  38.    stream[11] = curr_attr ;
  39.    stream[12] = selected_attr ;
  40.    count = 1 ;
  41.    for (i = sizeof(FT_HEADER) + num_fields*sizeof(FT_ENTRY) + 7 ; i < stream_len + 4 ; i += 5)
  42.       {
  43.       stream[i] = 0xF0 ;
  44.       stream[i+1] = count ;
  45.       stream[i+2] = 0xF2 ;
  46.       stream[i+3] = count++ ;
  47.       stream[i+4] = curr_attr ;
  48.       }
  49.    stream[stream_len+1] = 0xF4 ;  /* move cursor to first field */
  50.    stream[stream_len+2] = 1 ;
  51.    stream[stream_len+3] = WS_FLDRESET ;
  52.    return stream ;
  53. }
  54.  
  55. /*=============================================*/
  56. /* TVfld_build_entry   fill in an entry in a   */
  57. /*                     previously started      */
  58. /*                     field table definition  */
  59. /*   Ralf Brown 7/5/88                         */
  60. /*=============================================*/
  61.  
  62. void pascal TVfld_build_entry(BYTE *stream,int field,int upleftrow,int upleftcol,
  63.                               int lowrightrow,int lowrightcol,int type,int modifier,
  64.                               int color,int key2)
  65. {
  66.    stream += 7 ;                  /* skip stream header and opcode */
  67.    if (field >= 1 && field <= stream[1])
  68.       {
  69.       stream += sizeof(FT_HEADER) ;  /* skip field table header */
  70.       stream += (sizeof(FT_ENTRY) * (field-1)) ;
  71.       stream[0] = upleftrow ;
  72.       stream[1] = upleftcol ;
  73.       stream[2] = lowrightrow ;
  74.       stream[3] = lowrightcol ;
  75.       stream[4] = type ;
  76.       stream[5] = modifier ;
  77.       stream[6] = color ;
  78.       stream[7] = key2 ;
  79.       }
  80. }
  81.  
  82. /*=============================================*/
  83. /* TVfld_build_color  set the field's attribute*/
  84. /*   Ralf Brown 7/5/88                         */
  85. /*=============================================*/
  86.  
  87. void pascal TVfld_build_color(BYTE *stream,int field,int attr)
  88. {
  89.    stream += 7 ;  /* skip stream header and opcode */
  90.    if (field >= 1 && field <= stream[1])
  91.       {
  92.       stream += stream[1] * sizeof(FT_ENTRY) + sizeof(FT_HEADER) ;
  93.       stream[5*field-1] = attr ;
  94.       }
  95. }
  96.  
  97. /*=============================================*/
  98. /* TVfld_build_cursor  set which field the     */
  99. /*                     cursor will start in    */
  100. /*   Ralf Brown 7/10/88                        */
  101. /*=============================================*/
  102.  
  103. void pascal TVfld_build_cursor(BYTE *stream,int field)
  104. {
  105.    if (field >= 1 && field <= stream[8])
  106.       stream[(*(int *)(stream+2))+2] = field ;
  107. }
  108.  
  109. /* End of TVFBUILD.C */
  110.